//
//  IntroScrollViewController.m
//  yigou
//
//  Created by wangdianlei on 2017/2/6.
//  Copyright © 2017年 hanyiwang. All rights reserved.
//

#import "IntroScrollViewController.h"

static const NSInteger maxIntro = 3;

@interface IntroScrollViewController ()

@property (weak, nonatomic) IBOutlet UIScrollView *scrollview;

@end

@implementation IntroScrollViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    self.view.backgroundColor = NavigationColor;
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.scrollview.contentSize = CGSizeMake(ScreenWidth * maxIntro, ScreenHeight);
    self.scrollview.backgroundColor = [UIColor whiteColor];
//    NSString *deviceType = [DeviceHelper getPhoneType];
    BOOL bigPic = YES;
//    if ([deviceType isEqualToString:@"iPhone4_4s"]) {
//        bigPic = NO;
//    }
    NSString *picname = @"";
    for (int i = 0; i < maxIntro; i++) {
        if (bigPic) {
            picname = [NSString stringWithFormat:@"bigintro%d.png", i + 1];
        } else {
            picname = [NSString stringWithFormat:@"smallintro%d.png", i + 1];
        }
        UIImageView *imageview = [[UIImageView alloc] initWithImage:[UIImage imageNamed:picname]];
        imageview.frame = CGRectMake(i * ScreenWidth, 0, ScreenWidth, ScreenHeight);
        imageview.contentMode = UIViewContentModeScaleAspectFill;
        [self.scrollview addSubview:imageview];
        if (i == maxIntro - 1) {
            imageview.userInteractionEnabled = YES;
            UITapGestureRecognizer* singleRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(enterApp:)];
            singleRecognizer.numberOfTapsRequired = 1;
            [imageview addGestureRecognizer:singleRecognizer];
        }
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)enterApp:(UITapGestureRecognizer *)recognizer {
    if (self.delegate && [self.delegate respondsToSelector:@selector(beginApp)]) {
        [self.delegate beginApp];
    }
}

@end
